package b.b.g.i;

import android.content.Context;
import android.content.res.Resources;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnKeyListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.PopupWindow.OnDismissListener;
import b.b.h.u;

/* compiled from: StandardMenuPopup */
public final class q extends k implements OnDismissListener, OnItemClickListener, m, OnKeyListener {
    public final Context b;
    public final g c;
    public final f d;
    public final boolean e;
    public final int f;
    public final int g;
    public final int h;
    public final u i;
    public final OnGlobalLayoutListener j = new a();
    public final OnAttachStateChangeListener k = new b();
    public OnDismissListener l;
    public View m;
    public View n;
    public b.b.g.i.m.a o;
    public ViewTreeObserver p;
    public boolean q;
    public boolean r;
    public int s;
    public int t = 0;
    public boolean u;

    /* compiled from: StandardMenuPopup */
    public class a implements OnGlobalLayoutListener {
        public void onGlobalLayout() {
            if (q.this.b()) {
                q qVar = q.this;
                if (!qVar.i.y) {
                    View view = qVar.n;
                    if (view == null || !view.isShown()) {
                        q.this.dismiss();
                    } else {
                        q.this.i.d();
                    }
                }
            }
        }
    }

    /* compiled from: StandardMenuPopup */
    public class b implements OnAttachStateChangeListener {
        public void onViewAttachedToWindow(View view) {
        }

        public void onViewDetachedFromWindow(View view) {
            ViewTreeObserver viewTreeObserver = q.this.p;
            if (viewTreeObserver != null) {
                if (!viewTreeObserver.isAlive()) {
                    q.this.p = view.getViewTreeObserver();
                }
                q qVar = q.this;
                qVar.p.removeGlobalOnLayoutListener(qVar.j);
            }
            view.removeOnAttachStateChangeListener(this);
        }
    }

    public q(Context context, g gVar, View view, int i, int i2, boolean z) {
        this.b = context;
        this.c = gVar;
        this.e = z;
        this.d = new f(gVar, LayoutInflater.from(context), z, 2131492883);
        this.g = i;
        this.h = i2;
        Resources resources = context.getResources();
        this.f = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(2131165207));
        this.m = view;
        this.i = new u(context, null, i, i2);
        gVar.b(this, context);
    }

    public void a(g gVar, boolean z) {
        if (gVar == this.c) {
            dismiss();
            b.b.g.i.m.a aVar = this.o;
            if (aVar != null) {
                aVar.a(gVar, z);
            }
        }
    }

    public boolean b() {
        return !this.q && this.i.b();
    }

    /* JADX WARNING: Removed duplicated region for block: B:32:0x00ca  */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x00c9 A:{RETURN} */
    public void d() {
        /*
        r7 = this;
        r0 = r7.b();
        r1 = 0;
        r2 = 1;
        if (r0 == 0) goto L_0x000b;
    L_0x0008:
        r1 = 1;
        goto L_0x00c7;
    L_0x000b:
        r0 = r7.q;
        if (r0 != 0) goto L_0x00c7;
    L_0x000f:
        r0 = r7.m;
        if (r0 != 0) goto L_0x0015;
    L_0x0013:
        goto L_0x00c7;
    L_0x0015:
        r7.n = r0;
        r0 = r7.i;
        r0 = r0.z;
        r0.setOnDismissListener(r7);
        r0 = r7.i;
        r0.q = r7;
        r0.s(r2);
        r0 = r7.n;
        r3 = r7.p;
        if (r3 != 0) goto L_0x002d;
    L_0x002b:
        r3 = 1;
        goto L_0x002e;
    L_0x002d:
        r3 = 0;
    L_0x002e:
        r4 = r0.getViewTreeObserver();
        r7.p = r4;
        if (r3 == 0) goto L_0x003b;
    L_0x0036:
        r3 = r7.j;
        r4.addOnGlobalLayoutListener(r3);
    L_0x003b:
        r3 = r7.k;
        r0.addOnAttachStateChangeListener(r3);
        r3 = r7.i;
        r3.p = r0;
        r0 = r7.t;
        r3.l = r0;
        r0 = r7.r;
        r3 = 0;
        if (r0 != 0) goto L_0x005b;
    L_0x004d:
        r0 = r7.d;
        r4 = r7.b;
        r5 = r7.f;
        r0 = b.b.g.i.k.n(r0, r3, r4, r5);
        r7.s = r0;
        r7.r = r2;
    L_0x005b:
        r0 = r7.i;
        r4 = r7.s;
        r0.r(r4);
        r0 = r7.i;
        r4 = 2;
        r0 = r0.z;
        r0.setInputMethodMode(r4);
        r0 = r7.i;
        r4 = r7.a;
        java.util.Objects.requireNonNull(r0);
        if (r4 == 0) goto L_0x0079;
    L_0x0073:
        r5 = new android.graphics.Rect;
        r5.<init>(r4);
        goto L_0x007a;
    L_0x0079:
        r5 = r3;
    L_0x007a:
        r0.x = r5;
        r0 = r7.i;
        r0.d();
        r0 = r7.i;
        r0 = r0.c;
        r0.setOnKeyListener(r7);
        r4 = r7.u;
        if (r4 == 0) goto L_0x00b9;
    L_0x008c:
        r4 = r7.c;
        r4 = r4.m;
        if (r4 == 0) goto L_0x00b9;
    L_0x0092:
        r4 = r7.b;
        r4 = android.view.LayoutInflater.from(r4);
        r5 = 2131492882; // 0x7f0c0012 float:1.8609228E38 double:1.0530974074E-314;
        r4 = r4.inflate(r5, r0, r1);
        r4 = (android.widget.FrameLayout) r4;
        r5 = 16908310; // 0x1020016 float:2.387729E-38 double:8.353815E-317;
        r5 = r4.findViewById(r5);
        r5 = (android.widget.TextView) r5;
        if (r5 == 0) goto L_0x00b3;
    L_0x00ac:
        r6 = r7.c;
        r6 = r6.m;
        r5.setText(r6);
    L_0x00b3:
        r4.setEnabled(r1);
        r0.addHeaderView(r4, r3, r1);
    L_0x00b9:
        r0 = r7.i;
        r1 = r7.d;
        r0.p(r1);
        r0 = r7.i;
        r0.d();
        goto L_0x0008;
    L_0x00c7:
        if (r1 == 0) goto L_0x00ca;
    L_0x00c9:
        return;
    L_0x00ca:
        r0 = new java.lang.IllegalStateException;
        r1 = "StandardMenuPopup cannot be used without an anchor";
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.b.g.i.q.d():void");
    }

    public void dismiss() {
        if (b()) {
            this.i.dismiss();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:20:0x0070  */
    public boolean e(b.b.g.i.r r10) {
        /*
        r9 = this;
        r0 = r10.hasVisibleItems();
        r1 = 0;
        if (r0 == 0) goto L_0x0078;
    L_0x0007:
        r0 = new b.b.g.i.l;
        r3 = r9.b;
        r5 = r9.n;
        r6 = r9.e;
        r7 = r9.g;
        r8 = r9.h;
        r2 = r0;
        r4 = r10;
        r2.m317init(r3, r4, r5, r6, r7, r8);
        r2 = r9.o;
        r0.d(r2);
        r2 = b.b.g.i.k.v(r10);
        r0.h = r2;
        r3 = r0.j;
        if (r3 == 0) goto L_0x002a;
    L_0x0027:
        r3.p(r2);
    L_0x002a:
        r2 = r9.l;
        r0.k = r2;
        r2 = 0;
        r9.l = r2;
        r2 = r9.c;
        r2.c(r1);
        r2 = r9.i;
        r3 = r2.f;
        r4 = r2.i;
        if (r4 != 0) goto L_0x0040;
    L_0x003e:
        r2 = 0;
        goto L_0x0042;
    L_0x0040:
        r2 = r2.g;
    L_0x0042:
        r4 = r9.t;
        r5 = r9.m;
        r6 = b.i.k.o.a;
        r5 = r5.getLayoutDirection();
        r4 = android.view.Gravity.getAbsoluteGravity(r4, r5);
        r4 = r4 & 7;
        r5 = 5;
        if (r4 != r5) goto L_0x005c;
    L_0x0055:
        r4 = r9.m;
        r4 = r4.getWidth();
        r3 = r3 + r4;
    L_0x005c:
        r4 = r0.b();
        r5 = 1;
        if (r4 == 0) goto L_0x0064;
    L_0x0063:
        goto L_0x006d;
    L_0x0064:
        r4 = r0.f;
        if (r4 != 0) goto L_0x006a;
    L_0x0068:
        r0 = 0;
        goto L_0x006e;
    L_0x006a:
        r0.e(r3, r2, r5, r5);
    L_0x006d:
        r0 = 1;
    L_0x006e:
        if (r0 == 0) goto L_0x0078;
    L_0x0070:
        r0 = r9.o;
        if (r0 == 0) goto L_0x0077;
    L_0x0074:
        r0.b(r10);
    L_0x0077:
        return r5;
    L_0x0078:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.b.g.i.q.e(b.b.g.i.r):boolean");
    }

    public void f(boolean z) {
        this.r = false;
        f fVar = this.d;
        if (fVar != null) {
            fVar.notifyDataSetChanged();
        }
    }

    public ListView g() {
        return this.i.c;
    }

    public boolean h() {
        return false;
    }

    public void k(b.b.g.i.m.a aVar) {
        this.o = aVar;
    }

    public void l(g gVar) {
    }

    public void o(View view) {
        this.m = view;
    }

    public void onDismiss() {
        this.q = true;
        this.c.c(true);
        ViewTreeObserver viewTreeObserver = this.p;
        if (viewTreeObserver != null) {
            if (!viewTreeObserver.isAlive()) {
                this.p = this.n.getViewTreeObserver();
            }
            this.p.removeGlobalOnLayoutListener(this.j);
            this.p = null;
        }
        this.n.removeOnAttachStateChangeListener(this.k);
        OnDismissListener onDismissListener = this.l;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

    public boolean onKey(View view, int i, KeyEvent keyEvent) {
        if (keyEvent.getAction() != 1 || i != 82) {
            return false;
        }
        dismiss();
        return true;
    }

    public void p(boolean z) {
        this.d.c = z;
    }

    public void q(int i) {
        this.t = i;
    }

    public void r(int i) {
        this.i.f = i;
    }

    public void s(OnDismissListener onDismissListener) {
        this.l = onDismissListener;
    }

    public void t(boolean z) {
        this.u = z;
    }

    public void u(int i) {
        u uVar = this.i;
        uVar.g = i;
        uVar.i = true;
    }
}
